<?php
    $username = $_GET['username'];
    $link = mysqli_connect('localhost','root','root','2117');

    $sql = "SELECT * FROM `user` WHERE `username` = '$username'";

    $res = mysqli_query($link,$sql); 

    $result = mysqli_fetch_assoc($res);

    if(!$result){
        $resArr = ['code'=>1,'msg'=>'用户名可用'];
    }else{
        $resArr = ['code'=>0,'msg'=>'用户名不可用'];
    }

    echo json_encode($resArr);
?>